home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / cover.py < prev    next >
Text File  |  2008-11-17  |  6KB  |  198 lines

  1. # -*- coding: UTF-8 -*-
  2.  
  3. __revision__ = '$Id: cover.py 1040 2008-11-15 21:13:49Z mikej06 $'
  4.  
  5. # Copyright (c) 2005-2008 Vasco Nunes, Piotr O┼╝arowski
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. from reportlab.pdfgen import canvas
  25. from reportlab.lib.pagesizes import letter, A4
  26. from reportlab.lib.units import mm
  27. from reportlab.pdfbase import pdfmetrics
  28. from reportlab.pdfbase.ttfonts import TTFont
  29. from reportlab.platypus import Image
  30. from reportlab.lib import colors
  31. import sys
  32. import string
  33. import os, gtk
  34. import version
  35. import gutils
  36. import pango
  37.  
  38. exec_location = os.path.abspath(os.path.dirname(sys.argv[0]))
  39.  
  40. def cover_image(self,number):
  41.     filename = gutils.file_chooser(_("Select image"), \
  42.         action=gtk.FILE_CHOOSER_ACTION_OPEN, \
  43.         buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, \
  44.             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
  45.     if filename[0]:
  46.         cover_image_process(self, filename[0], number)
  47.  
  48. def cover_image_process(self, filename, number):
  49.     size = self.widgets['print_cover']['ci_size'].get_active()
  50.     print_number = self.widgets['print_cover']['ci_number'].get_active()
  51.  
  52.     if self.config.get('font', '')!='':
  53.         fontName = "custom_font"
  54.         pdfmetrics.registerFont(TTFont(fontName,self.config.get('font', '')))
  55.     else:
  56.         fontName = "Helvetica"
  57.  
  58.     if size == 0:
  59.         #standard
  60.         cover_x=774
  61.         cover_y=518
  62.     elif size == 1:
  63.         #slim
  64.         cover_x=757;
  65.         cover_y=518
  66.     else:
  67.         #double slim
  68.         cover_x=757
  69.         cover_y=518
  70.  
  71.     # A4 landscape definition
  72.     pageWidth = 842
  73.     pageHeight = 595
  74.  
  75.     # hardcoded to A4
  76.     pos_x=(pageWidth-cover_x)/2;
  77.     pos_y=(pageHeight-cover_y)/2;
  78.  
  79.     # make a pdf
  80.     # using a truetype font with unicode support
  81.     c = canvas.Canvas(os.path.join(self.griffith_dir, "cover.pdf"), \
  82.         (pageWidth, pageHeight))
  83.     c.setFont(fontName, 8)
  84.     # copyright line
  85.     c.drawString(20, 20 ,_("Cover generated by Griffith v").encode('utf-8') + \
  86.         version.pversion+" (C) 2004-2007 Vasco Nunes/Piotr Ozarowski - "+ \
  87.         _("Released Under the GNU/GPL License").encode('utf-8'))
  88.  
  89.     # get movie information from db
  90.     movie = self.db.Movie.get_by(number=number)
  91.     if movie is not None:
  92.         c.drawImage(filename, pos_x, pos_y, cover_x, cover_y)
  93.         if print_number == True:
  94.             c.setFillColor(colors.white)
  95.             c.rect((pageWidth/2)-13, 520, 26, 70, fill=1, stroke=0)
  96.             c.setFillColor(colors.black)
  97.             c.setFont(fontName, 10)
  98.             c.drawCentredString(pageWidth/2, 530, number)
  99.  
  100.     # draw cover area
  101.     c.rect(pos_x, pos_y, cover_x, cover_y)
  102.  
  103.     c.showPage()
  104.     c.save()
  105.     self.widgets['print_cover']['window_simple'].hide()
  106.     cover_file = os.path.join(self.griffith_dir, "cover.pdf")
  107.     if self.windows:
  108.         os.popen3("\"" + cover_file + "\"")
  109.     else:
  110.         os.popen3(self.pdf_reader + " " + cover_file)
  111.  
  112. def cover_simple(self, number):
  113.     size = self.widgets['print_cover']['cs_size'].get_active()
  114.     print_number = self.widgets['print_cover']['cs_include_movie_number'].get_active()
  115.     poster = self.widgets['print_cover']['cs_include_poster'].get_active()
  116.  
  117.     if self.config.get('font', '')!='':
  118.         fontName = "custom_font"
  119.         pdfmetrics.registerFont(TTFont(fontName,self.config.get('font', '')))
  120.     else:
  121.         fontName = "Helvetica"
  122.  
  123.     if size == 0:
  124.         #standard
  125.         cover_x=774
  126.         cover_y=518
  127.     elif size == 1:
  128.         #slim
  129.         cover_x=757;
  130.         cover_y=518
  131.     else:
  132.         #double slim
  133.         cover_x=757
  134.         cover_y=518
  135.  
  136.     # A4 landscape definition
  137.     pageWidth = 842
  138.     pageHeight = 595
  139.  
  140.     # hardcoded to A4
  141.     pos_x=(pageWidth-cover_x)/2;
  142.     pos_y=(pageHeight-cover_y)/2;
  143.     # make a pdf
  144.     c = canvas.Canvas(os.path.join(self.griffith_dir, "cover.pdf"), (pageWidth, pageHeight))
  145.     c.setFont(fontName,8)
  146.  
  147.     # copyright line
  148.     c.drawString(20,20,_("Cover generated by Griffith v").encode('utf-8') + \
  149.         version.pversion+" (C) 2004-2007 Vasco Nunes/Piotr Ozarowski - "+ \
  150.         _("Released Under the GNU/GPL License").encode('utf-8'))
  151.  
  152.     # draw cover area
  153.     c.rect(pos_x, pos_y, cover_x, cover_y)
  154.  
  155.     # get movie information from db
  156.     movie = self.db.Movie.get_by(number=number)
  157.     if movie is not None:
  158.         if print_number == True:
  159.             c.setFont(fontName, 10)
  160.             c.drawCentredString(pageWidth/2, 530, number)
  161.  
  162.         c.setFont(fontName, 16)
  163.         c.rotate(90)
  164.         c.drawString(60, (-pageWidth/2)-8, movie.o_title.encode('utf-8'))
  165.         c.rotate(-90)
  166.         if movie.image is not None and movie.image != '':
  167.             tmp_dest = self.locations['posters']
  168.             image = str(os.path.join(tmp_dest, str(movie.image)+".jpg"))
  169.             c.drawImage(image, x=(pageWidth-30)/2, y=470, width=30, height=50)
  170.         # print movie info
  171.         c.setFont(fontName, 8)
  172.         textObject = c.beginText()
  173.         textObject.setTextOrigin(pageWidth-cover_x, 300)
  174.         textObject.setFont(fontName, 8)
  175.         textObject.textLine(_("Original Title").encode('utf-8')+': '+str(movie.o_title).encode('utf-8'))
  176.         textObject.textLine(_("Title").encode('utf-8')+': '+str(movie.title).encode('utf-8'))
  177.         textObject.textLine("")
  178.         textObject.textLine(_("Director").encode('utf-8')+': '+str(movie.director).encode('utf-8'))
  179.         textObject.textLine("")
  180.         textObject.textLine(_("Running Time").encode('utf-8')+': '+str(movie.runtime).encode('utf-8')+ _(" min").encode('utf-8'))
  181.         textObject.textLine(_("Country").encode('utf-8')+': '+str(movie.country).encode('utf-8'))
  182.         textObject.textLine(_("Genre").encode('utf-8')+': '+str(movie.genre).encode('utf-8'))
  183.         textObject.textLine("")
  184.         c.drawText(textObject)
  185.         # draw bigger poster image
  186.         if poster == True and movie.image is not None:
  187.             c.drawImage(image, x=(pageWidth-(pageWidth-cover_x)-235), y=(pageHeight/2)-125, width=180, height=250)
  188.     c.showPage()
  189.     c.save()
  190.     self.widgets['print_cover']['window_simple'].hide()
  191.     cover_file = os.path.join(self.griffith_dir, "cover.pdf")
  192.     if self.windows:
  193.         os.popen3("\"" + cover_file + "\"")
  194.     elif self.mac:
  195.         os.popen3("open -a Preview" + " " + cover_file)
  196.     else:
  197.         os.popen3(self.pdf_reader + " " + cover_file)
  198.